# ------------------
# Techniques de développement
# M1 ALMA 2011-2012
# Pauline Folz - Adrien Quillet
# 
#
# ------------------
# Documentation
# ------------------
#
# CHECK_PYTHON
# ------------

AC_DEFUN([CHECK_PYTHON],
[
AC_MSG_CHECKING([for Python from 2.x])
AC_MSG_RESULT([])

for python in python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 ; do
	AC_CHECK_PROGS(python_bin_tmp, [$python])
	PYTHON_BIN=$python_bin_tmp
	if ! test "$PYTHON_BIN" = "" ; then
		AC_CHECK_LIB($PYTHON_BIN, main, PYTHON_LIB=$PYTHON_BIN, PYTHON_LIB=no)
		AC_CHECK_HEADER([$PYTHON_BIN/Python.h],
						[[PYTHON_HEADER=yes]],
						[PYTHON_HEADER=no])
		if ! test "$PYTHON_LIB" = no ; then
			if ! test "$PYTHON_HEADER" = no ; then
				break ;
			fi
		fi
	fi
done

if test "$PYTHON_BIN" = "" ; then
	PYTHON_BIN=no
fi
if test "$PYTHON_LIB" = "" ; then
	PYTHON_LIB=no
fi
if test "$PYTHON_HEADER" = "" ; then
	PYTHON_HEADER=no
fi

PYTHON_INCLUDE_DIR=""
if ! test "$PYTHON_HEADER" = "" ; then
	split_path=`echo $PATH | sed 's/:/ /g'`
	split_path="$split_path /usr/include /usr/local/include"
	for tmp in $split_path ; do
		if test -f "$tmp/$PYTHON_BIN/Python.h" ; then
			PYTHON_INCLUDE_DIR="$tmp/$PYTHON_BIN"
			break  ;
		fi
	done
fi

if ! test "$PYTHON_BIN" = no ; then
	if ! test "$PYTHON_LIB" = no ; then
		if ! test "$PYTHON_HEADER" = no ; then
			PYTHON_LIB="-l$PYTHON_LIB"
			AC_SUBST([PYTHON_BIN])
			AC_SUBST([PYTHON_LIB])
			AC_SUBST([PYTHON_INCLUDE_DIR])
		fi
	fi
fi

AC_MSG_RESULT([results of Python check :])
AC_MSG_RESULT([	Binary    : $PYTHON_BIN])
AC_MSG_RESULT([	Library   : $PYTHON_LIB])
AC_MSG_RESULT([	Python.h  : $PYTHON_HEADER])
AC_MSG_RESULT([	Incl. dir : $PYTHON_INCLUDE_DIR])

])
